package Hot100;

import DMSXL._2023Before.ListNode_.ListNode;

import java.util.ArrayList;

public class isPalindrome {
    public static void main(String[] args) {
        int[] listA = {1,2,1};
        ListNode headA = new ListNode(listA[0]);
        ListNode preA = headA;
        for (int i = 1; i < listA.length; i++) {
            ListNode temp = new ListNode(listA[i]);
            preA.next = temp;
            preA = preA.next;
        }
        System.out.println(isPalindrome(headA));
    }
    public static boolean isPalindrome(ListNode head) {
        if(head == null)
            return false;
        ArrayList<Integer> array = new ArrayList<>();
        int num = 0;
        while (head != null){
            array.add(head.val);
            num++;
            head = head.next;
        }

        for (int i = 0; i < array.size() / 2; i++) {
            if(array.get(i) != array.get(num - 1))
                return false;
            num --;
        }
        return true;


    }
}
